package com.nulldev.util.graphics.renderIt.api.demos;

import java.awt.Component;

import javax.swing.JFrame;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.RandomUtil;
import com.nulldev.util.graphics.renderIt.api.renderItAPI;
import com.nulldev.util.graphics.renderIt.api.renderItGraphicsInterface;
import com.nulldev.util.graphics.renderIt.api.core.IRenderCallback;
import com.nulldev.util.graphics.renderIt.api.core.IRenderCallbackMetadata;
import com.nulldev.util.graphics.renderIt.api.core.IRenderCanvas;
import com.nulldev.util.graphics.renderIt.api.core.renderItOutputType;
import com.nulldev.util.graphics.renderIt.renderer.global.rColor;
import com.nulldev.util.gui.swingAPI.Swing;
import com.nulldev.util.manage.legacy.FPSCounter;

public class RandomRectsDemo {

	public static void main(String[] args) {
		Swing.enableAA();
		Swing.enableJSO();
		final JFrame jfr = new JFrame("rIt! Demo: RandomRects");
		jfr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jfr.setLayout(new java.awt.BorderLayout(0, 0));
		final IRenderCanvas ic = renderItAPI.make_instance(renderItOutputType.RIT_OUTPUT_TYPE_AWT_FRAME, jfr);
		jfr.add((Component) ic.asAWTComponent());
		jfr.setBounds(50, 50, 400, 400);
		jfr.setVisible(true);
		final FPSCounter fpsc = new FPSCounter();
		ic.setRenderCallback(new IRenderCallback() {

			@Override
			public void onRender(final renderItGraphicsInterface iface, final IRenderCallbackMetadata metadata) {
				fpsc.timeStart();
				final int vw = iface.viewport_getWidth();
				final int vh = iface.viewport_getHeight();
				for (int i = 0; i < 1; i++) {
					final int px = RandomUtil.randInt(0, vw);
					final int py = RandomUtil.randInt(0, vh);
					final int rw = RandomUtil.randInt(10, vw - 10);
					final int rh = RandomUtil.randInt(10, vh - 10);
					iface.bd_fillRect(px, py, rw, rh, rColor.random());
				}
				fpsc.timeEnd();
				fpsc.callFPS();
				JVM.println("FPS: " + fpsc.getFPS() + ", Render Time: " + fpsc.avgRenderTimeS());
			}
		});
		ic.start();
		fpsc.start();
	}

}
